package com.googlecode.gwtbb.client.only.widget.basic;

import com.google.gwt.user.client.ui.*;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since May 7, 2008
 */
public class ModuleHeader extends Composite {
	private DockPanel panel;
	private Widget headerLeft;
	private Widget headerRight;

	public ModuleHeader() {
		this.panel = new DockPanel();
		initWidget(panel);
		panel.setWidth("100%");
		setStylePrimaryName("gwtbb-ModuleHeader");
	}

	public ModuleHeader(Widget header) {
		this();
		setHeaderLeft(header);
	}

	public ModuleHeader(Label header) {
		this((Widget)header);
		header.setStylePrimaryName("gwtbb-header");
	}

	public void removeHeaderRight() {
		if (headerRight != null)
			panel.remove(headerRight);
		headerRight = null;
	}

	public void setHeaderLeft(Widget header) {
		removeHeaderLeft();
		headerLeft = header;
		panel.add(header, DockPanel.WEST);
		panel.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_LEFT);
	}

	public void setHeaderRight(Widget header) {
		removeHeaderRight();
		headerRight = header;
		panel.add(header, DockPanel.EAST);
		panel.setCellHorizontalAlignment(header, HasHorizontalAlignment.ALIGN_RIGHT);
	}

	private void removeHeaderLeft() {
		if (headerLeft != null)
			panel.remove(headerLeft);
		headerLeft = null;
	}
}
